package cn.bdqn.controller;

import cn.bdqn.entity.SysUser;
import cn.bdqn.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;
import java.util.HashMap;
import java.util.Map;

/**
 * 系统用户(SysUser)表控制层
 *
 * @author makejava
 * @since 2020-12-01 14:48:30
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    public SysUser selectOne(Long id) {
        return this.sysUserService.queryById(id);
    }

    @RequestMapping("/userAll")
    @ResponseBody
    public Object userAll(){
        List<SysUser> list=sysUserService.userAll("");
        return list;
    }

    @RequestMapping("/userAllByName")
    @ResponseBody
    public Object userAllByName(@RequestBody SysUser sysUser){
        List<SysUser> list=sysUserService.userAll(sysUser.getUsername());
        return list;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody SysUser sysUser){
        Boolean flag=sysUserService.delete(sysUser.getUserId());
        return flag;
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(@RequestBody SysUser sysUser){
        int num=sysUserService.insert(sysUser);
        if(num>0){
            return true;
        }else{
            return false;
        }
    }

}
